import { useEffect, useState } from 'react';

/**
 * 自定义 Hook，根据窗口大小计算和更新最小高度。
 *
 * @returns {number} 当前的最小高度值。
 */
const useMinHeight = () => {
  const [minHeight, setMinHeight] = useState(500);

  useEffect(() => {
    /**
     * 根据窗口大小更新最小高度。
     */
    const updateMinHeight = () => {
      const newMinHeight = window.innerHeight - 64 - 16 * 2 - (18 + 24 * 2);
      setMinHeight(newMinHeight);
    };

    updateMinHeight();
    window.addEventListener('resize', updateMinHeight);

    return () => {
      window.removeEventListener('resize', updateMinHeight);
    };
  }, []);

  return minHeight;
};

export default useMinHeight;
